package validate

import "github.com/thedevsaddam/govalidator"

type (
	MapData map[string][]string
)

var data any
var rules map[string][]string
var messages map[string][]string

func SetData(request any) {
	data = request
}

func SetRules(rule map[string][]string) {
	rules = rule
}

func SetMessages(message map[string][]string) {
	messages = message
}

func SetRuleMessage(rule map[string][]string, message map[string][]string) {
	rules = rule
	messages = message
}

func Check() map[string][]string {
	if len(rules) > 0 && len(messages) > 0 {
		// 配置初始化
		opts := govalidator.Options{
			Data:          data,
			Rules:         rules,
			TagIdentifier: "valid", // 模型中的 Struct 标签标识符
			Messages:      messages,
		}

		// 开始验证
		return govalidator.New(opts).ValidateStruct()
	}
	return MapData{}
}
